﻿Imports System.Text

Namespace StatementSources
    Public Class CreateExaminationTypeStatementSource
        Inherits BaseStatementSource

        Public Sub New(name As String, description As String, isMajor As Boolean, createdBy As Integer)
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("INSERT [dbo].[ExaminationTypes] ")
            stringBuilder.Append("([Name],[Description],[IsMajor],[CreatedBy],[CreatedDttm],[ModifiedBy],[ModifiedDttm]) ")
            stringBuilder.Append("VALUES (@Name,@Description,@IsMajor,@CreatedBy,GETDATE(),@CreatedBy,GETDATE());")

            Sql = stringBuilder.ToString()

            Parameters.AddWithValue("@Name", name)
            Parameters.AddWithValue("@Description", description)
            Parameters.AddWithValue("@IsMajor", isMajor)
            Parameters.AddWithValue("@CreatedBy", createdBy)
        End Sub

    End Class

    Public Class ReadAllExaminationTypeStatementSource
        Inherits BaseStatementSource

        Public Sub New()
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("SELECT [ExaminationTypeId],[Name],[Description],[IsMajor],[CreatedBy],[CreatedDttm],[ModifiedBy],[ModifiedDttm] ")
            stringBuilder.Append("FROM [dbo].[ExaminationTypes];")

            Sql = stringBuilder.ToString()
        End Sub

        Public Sub New(isMajor As Boolean)
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("SELECT [ExaminationTypeId],[Name],[Description],[IsMajor],[CreatedBy],[CreatedDttm],[ModifiedBy],[ModifiedDttm] ")
            stringBuilder.Append("FROM [dbo].[ExaminationTypes] ")
            stringBuilder.Append("WHERE [IsMajor]=@IsMajor;")

            Sql = stringBuilder.ToString()

            Parameters.AddWithValue("@IsMajor", isMajor)
        End Sub

    End Class

    Public Class ReadByExaminationTypeIdStatementSource
        Inherits BaseStatementSource

        Public Sub New(examinationTypeId As Integer)
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("SELECT [ExaminationTypeId],[Name],[Description],[IsMajor],[CreatedBy],[CreatedDttm],[ModifiedBy],[ModifiedDttm] ")
            stringBuilder.Append("FROM [dbo].[ExaminationTypes] ")
            stringBuilder.Append("WHERE [ExaminationTypeId]=@ExaminationTypeId;")

            Sql = stringBuilder.ToString()

            Parameters.AddWithValue("@ExaminationTypeId", examinationTypeId)
        End Sub

    End Class

    Public Class UpdateExaminationTypeStatementSource
        Inherits BaseStatementSource

        Public Sub New(examinationTypeId As Integer, name As String, description As String, isMajor As Boolean, modifiedBy As Integer)
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("UPDATE [dbo].[ExaminationTypes] SET ")
            stringBuilder.Append("[Name]=ISNULL(@Name,[Name]),")
            stringBuilder.Append("[Description]=ISNULL(@Description,[Description]),")
            stringBuilder.Append("[IsMajor]=ISNULL(@IsMajor,[IsMajor]),")
            stringBuilder.Append("[ModifiedBy]=@ModifiedBy,")
            stringBuilder.Append("[ModifiedDttm]=GETDATE() ")
            stringBuilder.Append("WHERE [ExaminationTypeId]=@ExaminationTypeId;")

            Sql = stringBuilder.ToString()

            Parameters.AddWithValue("@ExaminationTypeId", examinationTypeId)
            Parameters.AddWithValue("@Name", name)
            Parameters.AddWithValue("@Description", description)
            Parameters.AddWithValue("@IsMajor", isMajor)
            Parameters.AddWithValue("@ModifiedBy", modifiedBy)
        End Sub

    End Class

    Public Class DeleteExaminationTypeStatementSource
        Inherits BaseStatementSource

        Public Sub New(examinationTypeId As Integer)
            Sql = "DELETE FROM [dbo].[ExaminationTypes] WHERE [ExaminationTypeId]=@ExaminationTypeId;"
            Parameters.AddWithValue("@ExaminationTypeId", examinationTypeId)
        End Sub

    End Class
End Namespace
